package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.dto.business.BusinessFollowBusinessDTO;
import com.qk.dto.business.BusinessSelectByPageDTO;
import com.qk.dto.business.BusinessSelectPoolByPageDTO;
import com.qk.entity.Business;
import com.qk.management.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 *  @author SHCJ
 *  @created 2025/10/15 11:25
 *  @description
 */
@RestController
@RequestMapping("/businesses")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

//  列表分页查询
    @GetMapping
    public Result selectByPage(BusinessSelectByPageDTO businessSelectByPageDTO) {
        return Result.success(businessService.selectByPage(businessSelectByPageDTO));
    }

//    添加商机
    @PostMapping
    public Result addBusiness(@RequestBody Business business) {
        businessService.addBusiness(business);
        return Result.success();
    }



//    分配商机
    @PutMapping("/assign/{businessId}/{userId}")
    public Result assignBusiness(@PathVariable  Integer businessId, @PathVariable Integer userId) {
        businessService.assignBusiness(businessId, userId);
        return Result.success();
    }

//    踢回公海
    @PutMapping("/back/{id}")
    public Result backToPool(@PathVariable Integer id) {
        businessService.backToPool(id);
        return Result.success();
    }

//    转客户
    @PostMapping("/toCustomer/{id}")
    public Result businessToCustomer(@PathVariable Integer id) {
        businessService.businessToCustomer(id);
        return Result.success();
    }

//    根据ID查询商机

    @GetMapping("/{id}")
    public Result getBusinessById(@PathVariable Integer id) {
        return Result.success(businessService.getBusinessById( id));
    }

//    跟进商机
    @PutMapping
    public Result followBusiness(@RequestBody BusinessFollowBusinessDTO dto) {
        businessService.followBusiness(dto);
        return Result.success();
    }

//   公海池列表查询
    @GetMapping("/pool")
    public Result selectPoolByPage(BusinessSelectPoolByPageDTO dto) {
        return Result.success(businessService.selectPoolByPage(dto));
    }
}
